<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('教材列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>序号：</label>
                                <input type="text" name="serialNumber"/>
                            </li>
                            <li>
                                <label>等级：</label>
                                <select id="grade" name="grade" class="form-control" type="text" ></select>
                            </li>
                            <li>
                                <label>教材名称：</label>
                                <input type="text" name="textbookName"/>
                            </li>
                            <li>
                                <label>出版社：</label>
                                <input type="text" name="press"/>
                            </li>
                            <li>
                                <label>主编：</label>
                                <input type="text" name="chiefEditor"/>
                            </li>
                            <li>
                                <label>副主编：</label>
                                <input type="text" name="deputyEditorInChief"/>
                            </li>
                            <li class="select-time">
                                <label>出版时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginPublicationTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endPublicationTime]"/>
                            </li>
                            <li>
                                <label>位次：</label>
                                <input type="text" name="rank"/>
                            </li>
                            <li>
                                <label>赋分：</label>
                                <input type="text" name="naturalEndowments"/>
                            </li>
                            <li>
                                <label>奖励：</label>
                                <input type="text" name="reward"/>
                            </li>
                            <li>
                                <label>上传人：</label>
                                <input type="text" name="applicant"/>
                            </li>
                            <li>
                                <label>审批：</label>
                                <input type="text" name="examineApprove"/>
                            </li>
                            <li>
                                <label>备案：</label>
                                <input type="text" name="keepOnRecord"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="ruoyi:material:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="ruoyi:material:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="ruoyi:material:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="ruoyi:material:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('ruoyi:material:edit')}]];
        var removeFlag = [[${@permission.hasPermi('ruoyi:material:remove')}]];
        var onRecordsDatas = [[${@dict.getType('sys_records')}]];
        var statusDatas = [[${@dict.getType('sys_status')}]];
        var prefix = ctx + "ruoyi/materialp";
        category();
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "教材",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'serialNumber',
                    title: '序号'
                },
                {
                    field: 'grade',
                    title: '等级'
                },
                {
                    field: 'textbookName',
                    title: '教材名称'
                },
                {
                    field: 'press',
                    title: '出版社'
                },
                {
                    field: 'chiefEditor',
                    title: '主编'
                },
                {
                    field: 'deputyEditorInChief',
                    title: '副主编'
                },
                {
                    field: 'publicationTime',
                    title: '出版时间'
                },
                {
                    field: 'rank',
                    title: '位次'
                },
                {
                    field: 'naturalEndowments',
                    title: '赋分'
                },
                {
                    field: 'reward',
                    title: '奖励'
                },
                // {
                //     field: 'applicant',
                //     title: '上传人'
                // },
                    {
                        title: '查看文件',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            if (row.file==null||row.file==''){
                                actions.push('<p>未提交</p> ');
                                return actions.join('');
                            }else{
                                actions.push('<a href=\''+row.file+'\' target="_blank" rel="nofollow">查看文件</a> ');
                                return actions.join('');
                            }
                            return actions.join('');
                        }
                    },
                {
                    field: 'examineApprove',
                    title: '审批',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'keepOnRecord',
                    title: '备案',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(onRecordsDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.keepOnRecord==1&&row.examineApprove==0){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="tijiao(\'' + row.id + '\')"><i class="fa fa-edit"></i>提交审批</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            //   actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }else if(row.keepOnRecord==0&&row.examineApprove==0){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="beian(\'' + row.id + '\')"><i class="fa fa-user"></i>备案</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');

                        }else if(row.keepOnRecord==3&&row.examineApprove==0){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="beian(\'' + row.id + '\')"><i class="fa fa-user"></i>重新备案</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');

                        }
                            //else if(row.examineApprove===1&&row.keepOnRecord===1){
                            //     actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="chehui(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤回</a> ');
                        // }
                        else if(row.examineApprove==2&&row.keepOnRecord==1){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="tijiao(\'' + row.id + '\')"><i class="fa fa-edit"></i>重新审批</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            //    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function tijiao(id) {
            $.modal.confirm("确认要提交申请吗?", function() {
                var url = prefix + "/tijiao";
                var data = { "id": id };
                $.operate.submit(url, "post", "json", data);
            });
        }

        function chehui(id) {
            $.modal.confirm("确认要撤回申请吗?", function() {
                var url = prefix + "/chehui";
                var data = { "id": id };
                $.operate.submit(url, "post", "json", data);
            });
        };
        function beian(id) {
            $.modal.confirm("确认要申报备案吗?", function () {
                var url = prefix + "/beian";
                var data = {"id": id};
                $.operate.submit(url, "post", "json", data);
            });
        }
        function category() {
            let uname="全部";
            $.ajax({
                url: prefix+"/grade",
                type:"get",
                dataType:"json",
                data:{},
                success:function (data) {
                    if (data.length>0){
                        $("#grade").append("<option>"+uname+"</option>")
                        for (i in data){
                            $("#grade").append("<option>"+data[i].grade+"</option>")
                        }
                    }else {
                        $("#grade").append("<option>暂无数据</option>")
                    }
                }
            })

        }
    </script>
</body>
</html>